#define _CRT_SECURE_NO_WARNINGS 1

int minOperations(int* nums, int numsSize, int k) {
    int* a = (int*)malloc(sizeof(int) * k);
    for (int i = 0; i < k; i++)
        a[i] = 0;
    for (int i = numsSize - 1; i >= 0; --i)
    {
        if (nums[i] <= k)
        {
            a[nums[i] - 1] = 1;
            for (int j = 0; j < k; j++)
            {
                if (a[j] == 0)
                {
                    break;
                }
                if (j == k - 1)
                {
                    printf("%d %d %d", i, j, a[0]);
                    free(a);
                    return numsSize - i;
                }
            }
        }
    }
    return numsSize;
}